﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using XamlMvp.Controls;
using XamlMvp;
using MvpPhonePivotApplication.Presenter;

namespace MvpPhonePivotApplication
{
    public partial class App : MvpApplication
    {
        private static MainViewModel viewModel = null;

        /// <summary>
        /// A static ViewModel used by the views to bind against.
        /// </summary>
        /// <returns>The MainViewModel object.</returns>
        public static MainViewModel ViewModel
        {
            get
            {
                // Delay creation of the view model until necessary
                if (viewModel == null)
                    viewModel = new MainViewModel();

                return viewModel;
            }
        }

        /// <summary>
        /// Constructor for the Application object.
        /// </summary>
        public App()
        {
            // Standard Silverlight initialization
            InitializeComponent();
        }

        protected override void Load(System.Windows.Threading.Dispatcher dispatcher)
        {
            dispatcher.BeginInvoke(ViewModel.LoadData);
        }

        protected override void InitializePresenters(XamlMvp.IPresenterBinder presenters)
        {
            presenters.RegisterPage<IViewPage<MainViewModel>, MainPresenter>((view, state) => new MainPresenter(view, ViewModel));
        }
    }
}